package com.zuoban.shiro.chain;

import com.zuoban.util.JwtUtil;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigInteger;

/**
 * 用户伪造请求头中的token
 */
@Component
@Order(1)
public class ForgeTokenChain implements AuthChain{

    @Resource
    private JwtUtil jwtUtil;

    @Override
    public BigInteger authentication(String token) {
        if (!jwtUtil.verify(token)){
            throw new RuntimeException("token解析异常，请重新登录");
        }else {
            return new BigInteger(jwtUtil.getClaims(token).getClaims().get("userId").asString());
        }
    }
}
